import 'package:flutter/material.dart';
import 'package:xvideos/hj_page/mine_business/mine_vip/vip_support_model.dart';
import 'package:xvideos/hj_page/pre_sale/pre_sale_provider.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

import 'newer_timer_vip_card_widget.dart';

class VipCardItem extends StatefulWidget {
  final Function()? callback;
  final bool isSelect;
  final VipProductModel model;

  const VipCardItem(this.model, {super.key, this.callback, this.isSelect = false});

  @override
  State<StatefulWidget> createState() {
    return _VipCardItemState();
  }
}

class _VipCardItemState extends State<VipCardItem> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: widget.callback,
        child: Container(
          child: Stack(
            children: [
              Positioned(
                left: 0,
                top: 9,
                bottom: 10,
                right: 0,
                child: Container(
                  child: NetworkImageLoader(
                    imageUrl: widget.isSelect ? widget.model.realSelectVipImage() : widget.model.realNormalVipImage(),
                    fit: BoxFit.fill,
                  ),
                ),
              ),
              if (widget.model.isPreSale && PreSaleProvider().canPayBalance())
                Positioned(
                  bottom: 20.5,
                  left: 41,
                  child: ValueListenableBuilder(
                      valueListenable: PreSaleProvider().deadline,
                      builder: (BuildContext context, dynamic value, Widget? child) => Text(
                            '剩余 $value',
                            style: TextStyle(color: Colors.white, fontSize: 10),
                          )),
                ),
              if (widget.model.actionDesc?.isNotEmpty ?? false)
                Positioned(
                  left: 0,
                  top: 0,
                  child: Container(
                    constraints: BoxConstraints(maxWidth: 111),
                    padding: EdgeInsets.symmetric(horizontal: 8, vertical: 3),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(12),
                        bottomRight: Radius.circular(12),
                      ),
                      gradient: LinearGradient(
                        colors: [
                          Color(0xffE1351F),
                          Color(0xffE1351F),
                        ],
                      ),
                    ),
                    // alignment: Alignment.center,
                    child: Text(
                      "${widget.model.actionDesc}",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        color: Color(0xE5FFFFFF),
                        fontWeight: FontWeight.w500,
                        fontSize: 10.0,
                      ),
                    ),
                  ),
                ),
              if (widget.model.productType == 5)
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    alignment: Alignment.bottomCenter,
                    child: NewerTimerVipCardWidget(),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}

class VipProductPrivilegeItem extends StatelessWidget {
  final NewPrivilege? model;
  final bool isShowOnePrivilege;

  const VipProductPrivilegeItem(this.model, {super.key, this.isShowOnePrivilege = false});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        NetworkImageLoader(
          imageUrl: model?.img ?? '',
          width: 28,
          height: 28,
          borderRadius: 18,
        ),
        3.sizeBoxH,
        Text(
          model?.privilegeName ?? '',
          maxLines: 1,
          style: TextStyle(fontSize: 11, fontWeight: FontWeight.w500, color: Colors.white.withOpacity(.9)),
        ),
        if (!isShowOnePrivilege) ...[
          3.sizeBoxH,
          Text(
            "${(model?.privilegeDesc?.split(" ").length ?? 0) > 1 ? model?.privilegeDesc?.split(" ")[0].trim() : model?.privilegeDesc?.split("\n")[0]}",
            maxLines: 1,
            style: TextStyle(
              color: Colors.white.withOpacity(.45),
              fontWeight: FontWeight.w400,
              fontSize: 9,
            ),
            textAlign: TextAlign.center,
          ),
          1.sizeBoxH,
          Text(
            "${(model?.privilegeDesc?.split(" ").length ?? 0) > 1 ? model?.privilegeDesc?.split(" ")[1].trim() : (model?.privilegeDesc?.split("\n").length ?? 0) > 1 ? model?.privilegeDesc?.split("\n")[1] : ""}",
            maxLines: 1,
            style: TextStyle(
              color: Colors.white.withOpacity(.45),
              fontWeight: FontWeight.w400,
              fontSize: 9,
            ),
            textAlign: TextAlign.center,
          ),
        ],
      ],
    );
  }
}
